using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 抽象SimulateBehaviour
/// </summary>
public partial class AbsHFSimulateBehaviour
{
    #region GameObject
    /// <summary>
    /// GameObject
    /// </summary>
    public GameObject gameObject { get; private set; }
    #endregion

    #region RectTransform
    /// <summary>
    /// RectTransform
    /// </summary>
    public RectTransform rectTransform { get; private set; }
    #endregion

    #region hasRectTransform 是否有RectTransform
    /// <summary>
    /// 是否有RectTransform
    /// </summary>
    public bool hasRectTransform { get; private set; }
    #endregion

    #region simulateGlobalId 模拟行为GlobalId
    /// <summary>
    /// 模拟行为GlobalId
    /// </summary>
    public long simulateGlobalId { get { return globalId; } }
    #endregion

    #region bindGameObjectInstanceId 绑定的GameObject组件InstanceId
    /// <summary>
    /// 绑定的GameObject组件InstanceId
    /// </summary>
    public int bindGameObjectInstanceId { get; private set; }
    #endregion

    #region isBindGameObject 是否绑定GameObejct
    /// <summary>
    /// 是否绑定GameObejct
    /// </summary>
    public bool isBindGameObject { get; private set; }
    #endregion

    #region BindGameObject
    /// <summary>
    /// 绑定GameObject
    /// </summary>
    /// <param name="_go">GameObject</param>
    public void BindGameObject(GameObject _go)
    {
        if (_go != null)
        {
            gameObject = _go;
            bindGameObjectInstanceId = _go.GetInstanceID();            
            rectTransform = _go.transform as RectTransform;
            hasRectTransform = rectTransform != null;
            if (hasRectTransform)
            {
                CollectUICtrls<ISF_UIBehaviour>();
            }
            OnBindSimulateBehaviourEvent();
            OnAfterBindGameObject();
            isBindGameObject = true;
        }
        else
        {
            HFP.HFError($"【{GetType().FullName}】 BindGameObject is null.");
        }
    }
    /// <summary>
    /// 绑定GameObject之后
    /// </summary>
    protected virtual void OnAfterBindGameObject() { }
    #endregion

    #region UnBindGameObject
    /// <summary>
    /// 解绑GameObject
    /// </summary>
    public void UnBindGameObject()
    {        
        OnClearBindGameObjectRefernce();
        OnAfterUnBindGameObject();
    }
    /// <summary>
    /// 解绑GameObject之后
    /// </summary>
    protected virtual void OnAfterUnBindGameObject() { }
    /// <summary>
    /// 清除绑定GameObject的引用
    /// </summary>
    void OnClearBindGameObjectRefernce()
    {
        OnUnBindSimulateBehaviourEvent();
        OnClearUICtrls();
        gameObject = null;        
        rectTransform = null;
        hasRectTransform = false;
        bindGameObjectInstanceId = 0;
        isBindGameObject = false;
    }
    #endregion
}